// strstr模拟实现

#include <iostream>
#include <assert.h>

char* strstr_self(const char* s1, const char* s2)
{
    const char* str1 = s1;
    const char* str2 = s2;
    const char* start = s1;
    while(*start)
    {
        str1 = start;
        str2 = s2;
        while(*str1 == *str2)
        {
            ++str1;
            ++str2;
        }
        if(*str2 == '\0')
        {
            return (char*)start;
        }
        ++start;
    }
    return NULL;
}

int main()
{
    char arr1[] = "adefghadefgh";
	char arr2[] = "efg";
	char* ret = strstr_self(arr1, arr2);
	if (ret == NULL)
	{
		printf("不存在\n");
	}
	else
	{
		printf("%s\n", ret);
	}

    return 0;
}
